package com.njtoyo.taxi.admin.rest.readfile.customer;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.njtoyo.taxi.admin.mapper.master.mapper.UserMapper;
import com.njtoyo.taxi.admin.rest.export.customer.CustomerPushTokenData;
import com.njtoyo.taxi.admin.utils.AuthUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class CustomerPushTokenListener extends AnalysisEventListener<CustomerQueryData> {
    private static final Logger LOGGER = LoggerFactory.getLogger(CustomerPushTokenListener.class);

    private List<CustomerPushTokenData> result;
    private final UserMapper userMapper;
    private final List<Long> ids = new ArrayList<>();

    public CustomerPushTokenListener(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public void invoke(CustomerQueryData item, AnalysisContext context) {
        ids.add(item.getId());
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

        result = userMapper.getPushTokenByIds(ids, AuthUtil.getDataAuthSqlWhere());
    }

    public List<CustomerPushTokenData> getResult() {
        return result;
    }
}
